import type { PageResponse } from './warehouse';

/**
 * 库位管理相关API
 */
import type { InventoryApi } from '#/models/inventory/inventory';

import { requestClient } from '#/api/request';

/**
 * 库位列表查询参数接口
 */
export interface LocationQueryParams {
  page?: number;
  pageSize?: number;
  warehouse_id?: number;
  name?: string;
  code?: string;
  status?: string;
  [key: string]: any;
}

/**
 * 获取库位列表
 * @param params - 查询参数，支持分页、过滤和排序
 * @returns 分页的库位列表数据
 */
export const getLocationList = (
  params?: LocationQueryParams,
): Promise<PageResponse<InventoryApi.Location>> => {
  return requestClient.get('/inventory/location/', { params });
};

/**
 * 获取单个库位详情
 * @param locationId - 库位ID
 * @returns 库位详情
 */
export const getLocation = (
  locationId: number,
): Promise<InventoryApi.Location> =>
  requestClient.get(`/inventory/location/${locationId}/`);

/**
 * 创建库位
 * @param data - 库位数据
 * @returns 创建成功的库位信息
 */
export const createLocation = (
  data: Partial<InventoryApi.Location>,
): Promise<InventoryApi.Location> =>
  requestClient.post('/inventory/location/', data);

/**
 * 更新库位
 * @param locationId - 库位ID
 * @param data - 更新的库位信息
 * @returns 更新后的库位信息
 */
export const updateLocation = (
  locationId: number,
  data: Partial<InventoryApi.Location>,
): Promise<InventoryApi.Location> =>
  requestClient.put(`/inventory/location/${locationId}/`, data);

/**
 * 删除库位
 * @param locationId - 库位ID
 * @returns 删除结果
 */
export const deleteLocation = (locationId: number): Promise<any> => {
  return requestClient.delete(`/inventory/location/${locationId}/`);
};
